<?php
	$ISTEXT=false;
	error_reporting (0); 
	if ($_REQUEST['logo']=="blaatschaap" and $SVG) {
		$filename = "images/sheep.svg";
		$filesize = filesize($filename);
		$file = fopen($filename, "rb");
		$image = fread($file,$filesize);
		fclose ($file);
		header ("Content-type: image/svg+xml");
		echo $image;

	} else { 
		if ($_REQUEST['logo']=="blaatschaap") $filename = "images/sheep.png";
		if ($_REQUEST['logo']=="nwtech") 			$filename = "images/nwt.jpg";
		if ($_REQUEST['logo']=="ovh") $filename="images/ovh_logo.gif";
		$imginfo  = getimagesize($filename);

		if (isset($_REQUEST['size'])) {
			$imgsize = escapestr($_REQUEST['size']);
		} else {
			$imgsize = 0;
		}

		if ($imginfo[0] < $imginfo[1]) $orientation = 0 ; else $orientation = 1 ; 
		$oh = $imginfo[1]; 
		$ow = $imginfo[0];

			$filesize = filesize($filename);
			$file = fopen($filename, "rb");
			$image = fread($file,$filesize);
			fclose ($file);


		if ($imgsize) {
			if ($orientation) {
				$nw = $imgsize;
				$nh = ($nw / $ow ) * $oh ;
			} else {
				$nh = $imgsize;
				$nw = ($nh / $oh ) * $ow ;
			}

			if ($_REQUEST['square']) {
				if ($orientation) {
					$offh = ($nw - $nh) /2; 
					$offw = 0;
					
				} else {
					$offw = ($nh - $nw) /2;
					$offh = 0;
					
				}
				$target = imagecreatetruecolor($imgsize,$imgsize);
				$color = imagecolorallocate($target,0,0,254); 
				imagefill($target,1,1,$color);
				imagecolortransparent($target,$color);

			} else {
				$offc = 0;
				$offh = 0;
				$target = imagecreatetruecolor($nw,$nh);
			}
			$source = imagecreatefromstring($image);
			$color = imagecolorallocate($target,0,0,254); 
			imagefill($target,1,1,$color);
			imagecolortransparent($target,$color);
			if ($_REQUEST['logo']=="nwtech") {
				$color = imagecolorallocate($target,255,255,255); 
				imagecolortransparent($target,$color);
			}
			imagecopyresized($target,$source,$offw,$offh,0,0,$nw,$nh,$ow,$oh);
			header ("Content-type: image/png");
			imagepng($target);
			imagedestroy($target);
			imagedestroy($source);
		} else {
		header ("Content-type: {$imginfo['mime']}");
		echo $image;		
		}
 }
?>
